package com.demo.demoproject.utils;

import org.jetbrains.annotations.NotNull;

import java.time.format.DateTimeFormatter;
import java.util.Random;

public class IdGenerator {
    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    /**
     * 生成10位数的UID
     * @return 十位数长度的UID
     */
    @NotNull
    public static String generateId() {
        long timestamp = System.currentTimeMillis() % (long) 1e10;
        int randomPart = new Random().nextInt(1000000);
        return String.format("%06d%04d", timestamp, randomPart % 10000);
    }

//    /**
//     * 生成22位数的id
//     * @param uid uid
//     * @return 生成的id
//     */
//    @Nullable
//    @Contract(pure = true)
//    public static String generateId(@NotNull String uid) {
//        // 确保 UID 不超过 10 位（22 - 14 = 8）
//        if (uid.length() > 10) {
//            return null;
//        }
//        // 获取当前时间并格式化
//        LocalDateTime now = LocalDateTime.now();
//        String timestamp = now.format(DATE_TIME_FORMATTER);
//        String id = uid + timestamp;
//        if (id.length() > 22) {
//            id = id.substring(id.length() - 22);
//        }
//
//        return id;
//    }
}
